<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" @selection-change="selectionChangeHandle" stripe>
          <el-table-column type="selection" header-align="center" align="center">
          </el-table-column>

          <el-table-column prop="id" :label="i18n('common.id')" width="70">
          </el-table-column>

          <el-table-column :label="i18n('user.user_role_name')" width="100">
            <template v-slot="scope">
              <span v-if="scope.row.role">
                {{ scope.row.role.title }}
              </span>
            </template>
          </el-table-column>

          <el-table-column prop="username" :label="i18n('user.username')" width="120">
          </el-table-column>

          <el-table-column prop="nickname" :label="i18n('user.nickname')">
            <template v-slot="scope">
              <dl class="table_dl">
                <dt>
                  <el-avatar :size="45" :src="scope.row.avatar">
                    <img src="@/assets/images/default/circle.png" />
                  </el-avatar>
                </dt>
                <dd class="table_dl_dd_all_30">
                  {{ i18n('user.nickname') }}： {{ scope.row.nickname }}
                </dd>
                <dd class="table_dl_dd_all_16_gray">
                  {{ i18n('user.apply.create_time') }}： {{ scope.row.create_time }}
                </dd>
              </dl>
            </template>
          </el-table-column>

          <el-table-column prop="sex" :label="i18n('user.sex')" width="120">
            <template v-slot="scope">
              {{ scope.row.sex.text }}
            </template>
          </el-table-column>

          <el-table-column :label="i18n('user.position')" width="120">
            <template v-slot="scope">
              <span v-if="scope.row.detail">
                {{ scope.row.detail.position }}
              </span>
            </template>
          </el-table-column>

          <el-table-column :label="i18n('common.audit_status')" width="120">
            <template v-slot="scope">
              <el-text :type="scope.row.audit_status.value == 0 ? 'danger' : 'success'">
                {{ scope.row.audit_status.text }}
              </el-text>
            </template>
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="260">
            <template v-slot="scope">
              <el-button v-if="scope.row.audit_status.value != 1" type="primary" icon="Edit" @click="clickHandle(scope.row.id)">
                {{ i18n('common.pass') }}
              </el-button>

              <el-button v-if="scope.row.audit_status.value != 1" type="danger" icon="Delete" @click="deleteHandle(scope.row.id)">
                {{ i18n('common.no_pass') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next, jumper, total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="user-apply-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, i18n, isAuth } = useBase()

  const model = ref('user/apply')

  const dataForm = reactive([])

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    handleStatus,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    selectionChangeHandle,
    getDataList,
    deleteHandle,
  } = useTable(model.value, dataForm)

  const clickHandle = (id) => {
    $http({
      url: $http.adornUrl(`/${model.value}/handle`),
      method: 'post',
      data: { id: id },
    }).then(({ data }) => {
      if (data && data.status === 200) {
        router.go(0)
      }
    })
  }

  onMounted(() => {
    getDataList(model)
  })
</script>
